#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char CH=getch();int fl=1;x=0;while(CH>'9'||CH<'0'){if(CH=='-')fl=-1;CH=getch();}while(CH<='9'&&CH>='0'){x=x*10+CH-48;CH=getch();}x*=fl;}
	template<typename T>void read_s(T &x){x="";char CH=getch();while(!(CH>='0'&&CH<='1'))CH=getch();while(CH>='0'&&CH<='1'){x+=CH;CH=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char CH) {if(p3-obuf<(1<<21))*p3++=CH;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=CH;}
	char CH[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)CH[++top]=x%10+48,x/=10;while(top)putch(CH[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);putch(' ');write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
int n;
#define pii pair<int,int>
#define fi first
#define se second
namespace Shiroha
{
	pii t[1000005<<2];
	#define ls (root<<1)
	#define rs (root<<1|1)
	#define mid (l+r>>1)
	void insert(int x,pii v,int root=1,int l=1,int r=1e6+1)
	{
		if(l==r) return t[root]=v,void();
		if(x<=mid) insert(x,v,ls,l,mid);
		else insert(x,v,rs,mid+1,r);
		t[root]=min(t[ls],t[rs]);
	}
	pii query(int x,int y,int root=1,int l=1,int r=1e6+1)
	{
		if(l>=x&&r<=y) return t[root];
		pii res={100000000,0};
		if(x<=mid) res=min(res,query(x,y,ls,l,mid));
		if(y>mid) res=min(res,query(x,y,rs,mid+1,r));
		return res;
	}
}
int ans;
int lg[1000005];
namespace Shiki
{
	int trie[1000005][2],dep[1000005],cnt=1,sz[1000005];
	inline int insert(string s)
	{
		int p=1;
		for(int i=0;i<s.size();i++)
		{
			if(!trie[p][s[i]-'0']) trie[p][s[i]-'0']=++cnt,dep[cnt]=dep[p]+1;
			p=trie[p][s[i]-'0'];
		}
		return p;
	}
	int L[1000005],R[1000005],dfn;
	void dfs(int u)
	{
		L[u]=++dfn;
		for(int i=0;i<=1;i++) if(trie[u][i]) dfs(trie[u][i]);
		R[u]=dfn;
	}
	void extend(int x)
	{
		pii tmp=Shiroha::query(L[x],R[x]);
		int p=tmp.se;ans+=tmp.fi-dep[x];
		++sz[p];
		int ndep,fl=0;
		for(int i=0;i<=1;i++) fl+=!trie[p][i];
		if(fl==1) ndep=dep[p]+lg[sz[p]-1]+2,Shiroha::insert(L[p],{ndep+1,p});
		else ndep=dep[p]+lg[sz[p]-1]+1,Shiroha::insert(L[p],{ndep+1,p});
	}
}using namespace Shiki;
int pos[100005];
signed main()
{
	freopen("id.in","r",stdin);
	freopen("id.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
	{
		string s;read_s(s);
		pos[i]=insert(s);
	}
	dfs(1);
	for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
	for(int i=1;i<=cnt;i++)
	{
		int fl=0;
		for(int j=0;j<=1;j++) fl+=!trie[i][j];
		if(fl==2) sz[i]=1,Shiroha::insert(L[i],{dep[i],i});
		else if(fl==1) sz[i]=1,Shiroha::insert(L[i],{dep[i]+1,i});
		else Shiroha::insert(L[i],{100000000,i});
	}
	sort(pos+1,pos+n+1,[&](int x,int y){return dep[x]>dep[y];});
	for(int i=1;i<=n;i++) extend(pos[i]);
	write(ans);
	flush();
	return 0;
}

